package com.ruoyi.banner.service.impl;/**
 * @Title:BannerService
 * @ClassName: ruoyi
 * @Description: TODO
 * @author: java
 * @time: 2024/2/27 8:52
 */
import com.ruoyi.banner.domain.Banner;
import com.ruoyi.banner.mapper.BannerMapper;
import com.ruoyi.banner.service.IBannerService;
import com.ruoyi.common.constant.DicConstants;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.http.HttpUtils;
import com.ruoyi.system.service.ISysConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @ClassName: BannerService
 * @Description: TODO
 * @author: java
 * @time: 2024/2/27 8:52
 */
@Service
public class BannerServiceImpl implements IBannerService {
    @Autowired
    private BannerMapper bannerMapper;
    @Autowired
    private ISysConfigService sysConfigService;


    /**
     * 查询Banner
     *
     * @param id Banner主键
     * @return Banner
     */
    @Override
    public Banner selectBannerById(Long id)
    {

        return bannerMapper.selectBannerById(id);
    }

    /**
     * 查询Banner列表
     *
     * @param banner Banner
     * @return Banner
     */
    @Override
    public List<Banner> selectBannerList(Banner banner)
    {
        return bannerMapper.selectBannerList(banner);
    }

    /**
     * 新增Banner
     *
     * @param banner Banner
     * @return 结果
     */
    @Override
    public int insertBanner(Banner banner)
    {
        banner.setCreateBy(SecurityUtils.getUserId());
        banner.setCreateType(DicConstants.BUSINESS_Manager.getCode());
        banner.setCreateTime(DateUtils.getNowDate());
        return bannerMapper.insertBanner(banner);
    }

    @Override
    public String converWechatOpenId(String code) {
        String appId = sysConfigService.selectConfigByKey("app_id_store");
        String appSecret = sysConfigService.selectConfigByKey("app_secret_store");
        String url = "https://api.weixin.qq.com/sns/jscode2session?" +
                "appid=" + appId + "&" + "secret=" + appSecret + "&" +
                "js_code=" + code + "&" +
                "grant_type=authorization_code";
        String content = HttpUtils.doGet(url, "UTF-8", 100, 1000);
        System.out.println("B端用户"+content);
        return content;
    }


    /**
     * 修改Banner
     *
     * @param banner Banner
     * @return 结果
     */
    @Override
    public int updateBanner(Banner banner)
    {
        banner.setUpdateBy(SecurityUtils.getUserId());
        banner.setUpdateType(DicConstants.BUSINESS_Manager.getCode());
        banner.setUpdateTime(DateUtils.getNowDate());
        return bannerMapper.updateBanner(banner);
    }

    /**
     * 批量删除Banner
     *
     * @param ids 需要删除的Banner主键
     * @return 结果
     */
    @Override
    public int deleteBannerByIds(Long[] ids)
    {
        return bannerMapper.deleteBannerByIds(ids);
    }


    /**
     * 批量逻辑删除Banner
     *
     * @param ids 需要删除的Banner主键
     * @return 结果
     */
    @Override
    public int logicDeleteBanner(Long[] ids,String delType,Long delUser)
    {
        return bannerMapper.logicDeleteBanner(ids,delType,delUser);
    }

    /**
     * 删除Banner信息
     *
     * @param id Banner主键
     * @return 结果
     */
    @Override
    public int deleteBannerById(Long id)
    {
        return bannerMapper.deleteBannerById(id);
    }
}
